home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / challenge / 12.03-Mar96 / 12.03ChallengeText.sit / 12.03 Challenge Text next >
Text File  |  1996-01-30  |  3KB  |  47 lines

  1. Words The Reverse
  2. Text input, of Block given a in words of order the place (in reverse) will that
  3. routine a write to is challenge the month this. Oops, what I meant to say was:
  4. This month, the Challenge is to write a routine that will reverse (in place)
  5. the order of words in a given block of input text. The prototype for the code
  6. you should write is:
  7.  
  8. pascal void ReverseTheWords(
  9.     const char *text,                        /* the words you should reverse */
  10.     const long numCharsIn                /* length of inputText in chars */
  11. );
  12. Specifically, ReverseTheWords should exchange the first word in the input text
  13. with the last word, the second word with the next-to-last word, etc. For the
  14. purpose of this Challenge, a word is defined as a continuous sequence of
  15. alphanumeric characters [a..zA..Z0..9]. Any nonalphanumeric characters should
  16. remain in their original positions and in their original order with respect to
  17. the new words; that is, punctuation, white space, and other characters between
  18. the first and second input words should, on output, be located between the new
  19. first and second words. As an example, ReverseTheWords would convert:
  20.  
  21.                 This, however, <-is-> a (difficult) test.
  22. into
  23.                 Test, difficult, <-a-> is (however) this.
  24.  
  25. As you can see from the example, there is one additional requirement. Your code
  26. needs to adjust the capitalization of words so that the n-th word is
  27. capitalized on output only if the n-th word was capitalized in the input text.
  28. There are no specific restrictions on the amount of auxiliary memory you may
  29. use (within reason), so you may allocate a few buffers of size numCharsIn
  30. should you need them. Remember, however, to deallocate any memory you allocate
  31. before returning, as I will be calling your code many times.
  32. Note that the prototype specifies the use of Pascal calling conventions. That
  33. is because this month we are conducting…
  34. A Language Experiment
  35. Over the past months, in response to suggestions from readers, we have made a
  36. number of changes to the Challenge, including migrating to PowerPC native code
  37. and expanding to other C compilers. Now we are experimenting with some
  38. additional changes. This month, for the first time, your solution to the
  39. Challenge can be coded in C, C++, or Pascal, using your choice among the MPW,
  40. Metrowerks, or Symantec compilers for these languages. Although either 68K or
  41. PowerPC code is permitted, I will be running your code on a PowerMac 8500, so
  42. native code is obviously recommended. The environment you choose must support
  43. linking your solution with test code written in C. Along with your solution,
  44. you should specify the intended environment, compiler and compiler options, or
  45. (better yet) provide a project file or make file that will generate a
  46. stand-alone application that calls your solution from C test code.
  47.